﻿Public Class Form1

    Private OriginalImage As Image
    Private Filters As List(Of Int16(,))


    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        OpenFileDialog1.Filter = "Image Files (*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png"
        OpenFileDialog1.FileName = ""
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            OriginalImage = Image.FromStream(OpenFileDialog1.OpenFile())
            PictureBox1.Image = OriginalImage.Clone()
            Text = OpenFileDialog1.FileName
            SaveToolStripMenuItem1.Enabled = True
            CloseToolStripMenuItem1.Enabled = True
        End If
    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem1.Click
        SaveFileDialog1.FileName = Text
        SaveFileDialog1.Filter = "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg"
        If Not IsNothing(PictureBox1.Image) Then
            If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                PictureBox1.Image.Save(SaveFileDialog1.FileName)
            End If
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub CloseToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem1.Click
        PictureBox1.Image = Nothing
    End Sub

    Private Sub AddFilterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFilterToolStripMenuItem.Click
        OpenFileDialog1.Filter = "Filter Files (*.txt)|*.txt"
        OpenFileDialog1.FileName = ""
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim filterFile As System.IO.FileStream = OpenFileDialog1.OpenFile()
            Dim filterFileReader As System.IO.StreamReader = New System.IO.StreamReader(filterFile)
            Dim filterString As String = filterFileReader.ReadToEnd()
            AddFilterFromString(filterString, OpenFileDialog1.SafeFileName)
        End If
    End Sub

    Private Sub AddFilterFromString(ByVal filter As String, ByVal name As String)
        'TODO: Maak een 2D array van ints wat het filter representeert, haal dit mbv regex uit filter en voeg een menuitem toe.

    End Sub
End Class
